package net.maku.needy.controller;

import cn.hutool.core.lang.Assert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.Result;
import net.maku.framework.security.user.SecurityUser;
import net.maku.framework.security.user.UserDetail;
import net.maku.needy.consts.DifficultyTypeEnum;
import net.maku.needy.service.NeedyMemberApplyService;
import net.maku.needy.vo.NeedyMemberApplyVO;
import org.springframework.web.bind.annotation.*;

/**
* 困难帮扶申请
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-20
*/
@RestController
@RequestMapping("needy/needyApply")
@Tag(name="困难帮扶申请")
@AllArgsConstructor
public class NeedyMemberApplyController {
    private final NeedyMemberApplyService needyMemberApplyService;

    @PostMapping("save")
    @Operation(summary = "申请")
    public Result<String> save(@RequestBody NeedyMemberApplyVO vo){
        UserDetail user = SecurityUser.getUser();
        Long memberId = user.getId();
        vo.setMemberId(memberId);
        check(vo);
        needyMemberApplyService.save(vo);
        return Result.ok();
    }

    private void check(NeedyMemberApplyVO apply){
        Integer difficultyType = apply.getDifficultyType();
        DifficultyTypeEnum difficultyTypeEnum = DifficultyTypeEnum.fromValue(difficultyType);
        switch (difficultyTypeEnum){
            case ASSIST_LEARNING:
                Assert.notBlank(apply.getStudentName(),"学生姓名不能为空");
                Assert.notBlank(apply.getSchoolName(),"所在学校不能为空");
                Assert.notNull(apply.getAge(),"年龄不能为空");
                Assert.notBlank(apply.getPeriod(),"升学阶段不能为空");
                break;
            case BIRTH_ALLOWANCE:
                //Assert.notNull(apply.getBirthday(),"出生日期不能为空");
                Assert.notBlank(apply.getBirthHospital(),"出生医院不能为空");
                break;
            case MARRIAGE_ALLOWANCE:
                Assert.notNull(apply.getWeddingDate(),"结婚日期不能为空");
                break;
            case SICK_ASSISTANCE:
                Assert.notNull(apply.getPersonalAvgIncome(),"月平均收入不能为空");
                Assert.notNull(apply.getFamilyAvgIncome(),"家庭月平均收入不能为空");
                Assert.notNull(apply.getApplyAmount(),"申请金额不能为空");
                break;
            case RELATIVES_PASSED_AWAY_CONDOLENCE:
                Assert.notBlank(apply.getBankCard(),"本人银行卡号不能为空");
                Assert.notBlank(apply.getDepositBank(),"开户银行不能为空");
                Assert.notBlank(apply.getDirectKinshipRelationship(),"直系亲属关系不能为空");
                break;
            case LEGAL_AID:
                break;
        }
    }

}